<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryAccessForm" v-show="showSearch" :inline="true" label-width="68px">
            <el-form-item label="处理状态" prop="status">
                <el-select
                        v-model="queryParams.disposeStatus"
                        placeholder="特征任务处理状态"
                        clearable
                        style="width: 200px"
                        @change="handleQueryAccess"
                >
                    <el-option
                            v-for="dict in sys_access_status"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="采集编号" prop="collectId">
                <el-input
                    v-model="queryParams.collectId"
                    placeholder="请输入采集编号"
                    clearable
                    style="width: 120px"
                    @keyup.enter="handleQueryAccess"
                />
            </el-form-item>
            <el-form-item label="目标编号" prop="targetId">
                <el-input
                    v-model="queryParams.targetId"
                    placeholder="请输入目标编号"
                    clearable
                    style="width: 120px"
                    @keyup.enter="handleQueryAccess"
                />
            </el-form-item>
            <el-form-item label="创建时间" style="width: 308px">
                <el-date-picker
                        v-model="queryDateRange"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @change="handleQueryAccess"
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQueryAccess">搜索</el-button>
                <el-button icon="Refresh" @click="resetQueryAccess">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                        type="primary"
                        plain
                        icon="Plus"
                        @click="handleAddAccess"
                >新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="danger"
                        plain
                        icon="Delete"
                        :disabled="multiple"
                        @click="handleDeleteAccesses"
                >删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="warning"
                        plain
                        icon="Download"
                        @click="handleExport"
                        v-hasPermi="['system:role:export']"
                >导出</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getAccessList"></right-toolbar>
        </el-row>

        <!-- 表格数据 -->
        <el-table v-loading="loading" :data="accessList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
                label="序号"
                type="index"
                width="50"
                align="center">
                <template #default="scope">
                    {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
                </template>
            </el-table-column>
<!--            <el-table-column label="评估编号" prop="cnId" width="120" />-->
            <el-table-column label="处理状态" prop="disposeStatus"  width="80">
                <template #default="scope">
                    <dict-tag :options="sys_access_status" :value="scope.row.disposeStatus" />
                </template>
            </el-table-column>
            <el-table-column label="采集编号" align="center" key="collectId" prop="collectId" v-if="true" :show-overflow-tooltip="true" />
            <el-table-column label="目标编号" align="center" key="targetId" prop="targetId" v-if="true" :show-overflow-tooltip="true" />
<!--            <el-table-column label="采集时间" align="center" key="collectTime" prop="collectTime" v-if="true" :show-overflow-tooltip="true" >-->
<!--                <template #default="scope">-->
<!--                    <span>{{ parseTime(scope.row.collectTime) }}</span>-->
<!--                </template>-->
<!--            </el-table-column>-->
            <el-table-column label="射频频率" align="center" key="rfFreq" prop="rfFreq" v-if="true"/>
            <el-table-column label="采样速率" align="center" key="sampleRate" prop="sampleRate" v-if="true"/>
            <el-table-column label="记录格式" align="center" key="collectFormat" prop="collectFormat" v-if="true">
                <template #default="scope">
                    <dict-tag :options="sys_data_format_type" :value="scope.row.collectFormat" />
                </template>
            </el-table-column>
            <el-table-column label="正反谱" align="center" key="spectrum" prop="spectrum" v-if="true">
                <template #default="scope">
                    <dict-tag :options="sys_data_spectrum_type" :value="scope.row.spectrum" />
                </template>
            </el-table-column>
            <el-table-column label="数据地址" align="center" key="dataFile" prop="dataFile" v-if="false"/>
            <el-table-column label="载波数量" prop="carrierNum"/>
            <el-table-column label="最大信噪比" prop="maxSnr"/>
            <el-table-column label="最大浮动量" prop="maxSpan"/>
            <el-table-column label="质量等级" prop="qualityGrade"/>
            <el-table-column label="入库时间" align="center" key="createTime" prop="createTime" :show-overflow-tooltip="true">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
<!--                    <el-tooltip content="详细" placement="top" >-->
<!--                        <el-button link type="primary" icon="View" @click="handleDetails(scope.row)"></el-button>-->
<!--                    </el-tooltip>-->
                    <el-tooltip content="删除" placement="top" v-if="scope.row.disposeStatus == 2 || scope.row.disposeStatus == 3">
                        <el-button link type="primary" icon="Delete" @click="handleDeleteAccess(scope.row)" ></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>

        <pagination
                v-show="accessTotal > 0"
                :total="accessTotal"
                v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize"
                @pagination="getAccessList"
        />

        <!-- 添加任务对话框 -->
        <el-dialog :title="addAccessDialog.title" v-model="addAccessDialog.open" append-to-body fullscreen>
            <el-row :gutter="10" class="">
                <el-form :model="addAccessDialog.queryParams" ref="querySampleForm" :inline="true" v-show="addAccessDialog.showSearch" label-width="68px">
                    <el-form-item label="采集编号" prop="collectId">
                        <el-input
                            v-model="addAccessDialog.queryParams.collectId"
                            placeholder="请输入采集编号"
                            clearable
                            style="width: 120px"
                            @keyup.enter="handleQueryMetAnalogData"
                        />
                    </el-form-item>
                    <el-form-item label="目标编号" prop="targetId">
                        <el-input
                            v-model="addAccessDialog.queryParams.targetId"
                            placeholder="请输入目标编号"
                            clearable
                            style="width: 120px"
                            @keyup.enter="handleQueryMetAnalogData"
                        />
                    </el-form-item>
                    <el-form-item label="创建时间" style="width: 308px;">
                        <el-date-picker
                            v-model="addAccessDialog.queryDateRange"
                            value-format="YYYY-MM-DD"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="handleQueryMetAnalogData"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="Search" @click="handleQueryMetAnalogData">搜索</el-button>
                        <el-button icon="Refresh" @click="resetQueryMetAnalogData">重置</el-button>
                    </el-form-item>
                </el-form>
            </el-row>
            <el-row :gutter="10" class="">
                <right-toolbar v-model:showSearch="addAccessDialog.showSearch" @queryTable="handleQueryMetAnalogData" :columns="addAccessDialog.showColumns"></right-toolbar>
            </el-row>
            <el-row :gutter="10" class="">
                <el-table v-loading="addAccessDialog.loading" :data="addAccessDialog.dataList"  @selection-change="handleSelectionChangeMetAnalogData">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column
                        label="序号"
                        type="index"
                        width="50"
                        align="center">
                        <template #default="scope">
                            {{ (addAccessDialog.queryParams.pageNum - 1) * addAccessDialog.queryParams.pageSize + scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column label="id" align="center" key="cnId" prop="cnId" v-if="addAccessDialog.showColumns[0].visible" />
                    <el-table-column label="采集编号" align="center" key="collectId" prop="collectId" v-if="addAccessDialog.showColumns[1].visible" :show-overflow-tooltip="true" />
                    <el-table-column label="目标编号" align="center" key="targetId" prop="targetId" v-if="addAccessDialog.showColumns[2].visible" :show-overflow-tooltip="true" />
                    <el-table-column label="采集时间" align="center" key="collectTime" prop="collectTime" v-if="addAccessDialog.showColumns[3].visible" :show-overflow-tooltip="true" >
                        <template #default="scope">
                            <span>{{ parseTime(scope.row.collectTime) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="射频频率" align="center" key="rfFreq" prop="rfFreq" v-if="addAccessDialog.showColumns[4].visible"/>
                    <el-table-column label="采样速率" align="center" key="sampleRate" prop="sampleRate" v-if="addAccessDialog.showColumns[5].visible"/>
                    <el-table-column label="记录格式" align="center" key="collectFormat" prop="collectFormat" v-if="addAccessDialog.showColumns[6].visible">
                        <template #default="scope">
                            <dict-tag :options="sys_data_format_type" :value="scope.row.collectFormat" />
                        </template>
                    </el-table-column>
                    <el-table-column label="正反谱" align="center" key="spectrum" prop="spectrum" v-if="addAccessDialog.showColumns[7].visible">
                        <template #default="scope">
                            <dict-tag :options="sys_data_spectrum_type" :value="scope.row.spectrum" />
                        </template>
                    </el-table-column>
                    <el-table-column label="入库人" align="center" key="createBy" prop="createBy" v-if="addAccessDialog.showColumns[8].visible"/>
                    <el-table-column label="入库时间" align="center" key="createTime" prop="createTime" v-if="addAccessDialog.showColumns[9].visible" :show-overflow-tooltip="true"/>
                </el-table>
            </el-row>
            <el-row>
                <pagination
                        v-show="addAccessDialog.dataTotal > 0"
                        :total="addAccessDialog.dataTotal"
                        v-model:page="addAccessDialog.queryParams.pageNum"
                        v-model:limit="addAccessDialog.queryParams.pageSize"
                        @pagination="getMetAnalogDataList"
                />
            </el-row>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" :disabled="addAccessDialog.multiple" @click="submitAddAccess">确 定</el-button>
                    <el-button @click="cancelAddAccess">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script>

import RateView from "@/components/rateView/index.vue";
import {addDateRange, parseTime} from "@/utils/ruoyi";
import {
    deleteSysQualityAccessByIds,
    insertSysQualityAccessByMetAnalogDataIds,
    selectSysQualityAccessList
} from "@/api/signal/qualityAccess";
import {getMetAnalogDataUnAccess} from "@/api/signal/metAnalogData";
import {deleteRadioFeatureTask} from "@/api/signal/radioFeatureTask";

export default {
    name: "Access",
    components: {},
    props: [],
    data() {
        return {
            accessList:[],
            ids:[],
            multiple:true,//选中列表
            loading:false,
            accessTotal:0,
            showSearch:true,
            queryDateRange: [],
            addAccessDialog:{ //《服务样本选择》Dialog
                loading:false,
                open:false,
                title: '请选择需要质量评估的数据',//《服务样本选择》Dialog 的标题
                dataTotal:0,
                ids:[],
                multiple:true,//选中样本
                dataList:[],
                showSearch:true,
                disposeStatusOptions:[{label:'全部状态',value:0},{label:'已处理',value:1},{label:'未处理',value:2}],
                queryParams:{
                    pageNum: 1,
                    pageSize: 10,
                    targetId:"",
                    collectId:""
                },
                queryDateRange: [],
                showColumns: [
                    { key: 0, label: `Id`, visible: true },
                    { key: 1, label: `采集编号`, visible: true },
                    { key: 2, label: `目标编号`, visible: true },
                    { key: 3, label: `采集时间`, visible: true },
                    { key: 4, label: `射频频率`, visible: true },
                    { key: 5, label: `采样速率`, visible: true },
                    { key: 6, label: `记录格式`, visible: true },
                    { key: 7, label: `正反谱`, visible: true },
                    { key: 8, label: `入库人`, visible: true },
                    { key: 9, label: `入库时间`, visible: true }
                ]
            },
            queryParams:{
                pageNum: 1,
                pageSize: 10,
                disposeStatus: "",
                targetId:"",
                collectId:""
            },
            rules: {

            },
            sys_access_status: [],
            sys_data_format_type: [],
            sys_data_spectrum_type:[],
        }
    },
    computed: {},
    watch: {},
    created() {
        let { sys_access_status, sys_data_format_type, sys_data_spectrum_type} = this.useDict("sys_access_status","sys_data_format_type","sys_data_spectrum_type");
        this.sys_access_status = sys_access_status
        this.sys_data_format_type = sys_data_format_type
        this.sys_data_spectrum_type = sys_data_spectrum_type
    },
    mounted() {
        this.handleQueryAccess()
    },
    methods: {
        parseTime,
        //获取评估列表
        getAccessList(){
            this.loading = true
            selectSysQualityAccessList(addDateRange(this.queryParams, this.queryDateRange)).then(response => {
                this.accessList = response.rows
                this.accessTotal = response.total
                this.loading = false
            })
        },
        //重新搜搜
        handleQueryAccess() {
            this.queryParams.pageNum = 1
            this.getAccessList()
        },
        //重置搜索参数
        resetQueryAccess() {
            this.queryDateRange = []
            this.$refs['queryAccessForm'].resetFields()
            this.queryParams.disposeStatus=""
            this.handleQueryAccess()
        },
        //打开添加任务对话框
        handleAddAccess(){
            this.addAccessDialog.open = true
            this.handleQueryMetAnalogData()
        },
        handleSelectionChange(selection){ //添加任务样本列表复选框勾选
            this.ids = selection.map(item => item.cnId);
            this.multiple = !selection.length
        },
        handleDeleteAccesses(){ //删除任务
            const that = this
            this.$modal.confirm('是否确认删除编号为"' + this.ids + '"的数据项？').then(function () {
                deleteSysQualityAccessByIds(that.ids).then(response => {
                    that.$modal.msgSuccess(response.msg)
                    that.getAccessList()
                })
            })
        },
        handleDeleteAccess(row){
            const that = this
            let idList = []
            idList.push(row.cnId);
            this.$modal.confirm('是否确认删除编号为"' + idList + '"的数据项？').then(function () {
                deleteSysQualityAccessByIds(idList).then(response => {
                    that.$modal.msgSuccess(response.msg)
                    that.getAccessList()
                })
            })
        },
        getMetAnalogDataList(){
            this.addAccessDialog.loading = true
            getMetAnalogDataUnAccess(addDateRange(this.addAccessDialog.queryParams, this.addAccessDialog.queryDateRange)).then(response => {
                this.addAccessDialog.dataList = response.rows
                this.addAccessDialog.dataTotal = response.total
                this.addAccessDialog.loading = false
            })
        },
        handleQueryMetAnalogData() {
            this.addAccessDialog.queryParams.pageNum = 1
            this.getMetAnalogDataList()
        },
        resetQueryMetAnalogData() {
            this.addAccessDialog.queryDateRange = []
            this.$refs['queryAccessForm'].resetFields()
            this.handleQueryAccess()
        },
        handleSelectionChangeMetAnalogData(selection){
            this.addAccessDialog.ids = selection.map(item => item.cnId);
            this.addAccessDialog.multiple = !selection.length
        },
        submitAddAccess(){
            this.addAccessDialog.loading = true
            insertSysQualityAccessByMetAnalogDataIds(this.addAccessDialog.ids).then(response => {
                this.$modal.msgSuccess(response.msg);
                this.addAccessDialog.loading = false
                this.handleQueryAccess()
            })
            this.addAccessDialog.open = false
        },
        cancelAddAccess(){
            this.addAccessDialog.open = false
        },
    }
}
</script>

<style scoped>

</style>
<script setup>
</script>